<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@include file="include.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="js/metroui/js/jquery.dataTables.min.js"></script>
</head>
<body>
<input type="text" name="search" id="extra_search">
<table class="table striped hovered dataTable border bordered" id="dataTables-1">
                <thead>
                <tr>
                    <th class="text-left">fileid</th>
                    <th class="text-left">filename</th>
					<th class="text-left">uploadtime</th>
					<th class="text-left">操作</th>
                </tr>
                </thead>

                <tbody>
                </tbody>
            </table>
            <!--  
            <button class="button primary" id="b1">Get List</button>
               <a href="download.action">test_download</a>
               -->
    <script type="text/javascript">

    $(document).ready(function(){
    function ChangeSearch(){
    		   var ss=$("#extra_search").val();
				table1.ajax.url(encodeURI("testjson2.action?search="+ss)).load();
    	   }
    	 

    	 
   	$("#b1").click(function(){
				var s=$("#extra_search").val();
				
            	//table1.search("狂三");
            	//alert($("#extra_search").val());
            	alert(s);
            	
            	//table1.ajax.reload();
            	table1.ajax.url(encodeURI("testjson2.action?search="+s)).load();
            	//table1.draw();        		    
   		});
   	$("#extra_search").blur(function(){
		
   		ChangeSearch();      		    
	});
   	$("#extra_search").focus(function(){
   		$("#extra_search").keydown(function(e){ 
   			if(e.keyCode==13){ 
   				ChangeSearch();
   			}
   			
   		});
   		
   	});
	


   	
    var table1=$("#dataTables-1").DataTable( {
        "processing": true,
        "ordering": false, 
        "searching":false,
        serverSide: true,
        ajax:{
			url:"testjson2.action"
			//"type": "GET"
			//data:"search="+$("#extra_search").val()
			},
     
        	//dataSrc: 'result'

    	"oLanguage": {
    		"sLengthMenu": "每页显示 _MENU_ 条记录",
    		"sZeroRecords": "抱歉， 没有找到",
    		"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条",
    		"sInfoEmpty": "没有数据",
    		"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
    		"oPaginate": {
    		"sFirst": "首页",
    		"sPrevious": "前一页",
    		"sNext": "后一页",
    		"sLast": "尾页"
    		},
    		"sZeroRecords": "没有检索到数据"
    	},
    	
    	
    columns: [ 
    	{data:"fileid"},
    	
    	{data:"filename"},
    	{data:"uploadtime.time",render:function(data){
    		
    		return UnixToDate(data);
    	}
    	},
    	{"defaultContent":"<button class='button primary' onclick='download();'>下载</button>"}
    	]

	 }
    );

    $('#dataTables-1 tbody').on('click', 'button', function () {
        //var data1 = table1.row( $(this).parents('tr') ).data();
        //alert( data1[0] +"'s salary is: "+ data1[2] );
    	 var id=$(this).parent().parent().children("td").get(1).innerHTML; 
    	 //$.get("download.action",{dl_fileName:id},function(result){
    		 
    	 //});
    	 alert(id);
    	 window.location.href=encodeURI("download.action?dl_fileName="+id);
    	 
    	 
    } );
    
   	});
    	
   
   	function download(){
   		alert("dl");
   		
   	}

    
    function UnixToDate(unixTime) {
        var date=new Date(unixTime);
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = date.getDate() + ' ';
        h = date.getHours() + ':';
        m = date.getMinutes() + ':';
        s = date.getSeconds(); 
    	
        return Y+M+D+h+m+s;
    }


    </script>
</body>
</html>